home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 20
/
Cream of the Crop 20 (Terry Blount) (1996).iso
/
utility
/
bat_faq1.zip
/
BAT-FAQ.ASC
Wrap
Text File
|
1996-07-03
|
32KB
|
680 lines
THE BATPOWER FAQ,
or Frequently Asked Questions
| *** Last revision: 28 Jun 96 ***
+----------------------------------------------------------------+
| Table of Contents for | 14. Path over 128 characters |
| FREQUENTLY ASKED QUESTIONS, | 15. What is the 'MUF'? |
| (FAQ) for the BATPOWER Echo | 16. Recursion/Loops in a BAT |
|-------------------------------+ 17. Start-up screen rotation |
| 1. How to reboot in a BATch | 18. Tidying output from a BAT |
| 2. Communicate with a modem | 19. Using ANSI codes in a BAT |
| 3. Date & Time Use in a BAT | 20. REM or :: in a BATch |
| 4. Combine files into one | 21. Is bat run from Windows ? |
| 5. Formatting Disks Q&A | 22. Using Ctrl+Z in a BATch |
| 6. Getting errorlevel Q&A | 23. Zero byte files- questions |
| 7. Help with making a menu | 24. Banish 'Retry,Abort,Ignore'|
| 8. Is TSR loaded in memory ? | 25. Getting user BATch input |
| 9. Jump back to prior dir | 26. BATch Programming Books |
| 10. Find&Replace text in file | 27. BFDS FDN questions |
| 11. Low level HD format Q&A | 28. Scripts posted in BATPOWER |
||12. FOR..IN..DO Q&A's | 29. |
| 13. Out of Environment Q&A's | 30. |
+----------------------------------------------------------------+
1. HOW TO REBOOT IN A BATch
~~~~~~~~~~~~~~~~~~~~~~~~
Q: How do I reboot the PC from inside a batch file ?
A: ECHO G=FFFF:0 | DEBUG >NUL for MSDOS} these occasionally
ECHO GFFFF:0000 | SID >NUL for DRDOS} will give garbage
--------------------------------------------------------------
ECHO HPS╦>REBOOT.COM This seems reliable, most editors
REBOOT.COM will allow Alt+203 to get the ╦
Hold the ALT key while 2 0 3 is
entered at the r/h keypad (Numlock ON)
--------------------------------------------------------------
This DEBUG script will produce COLDBOOT.COM when you run it
------------------------------------+ thus: DEBUG<SCRIPT.EXT
If your using BNU type: BNU /B |
If your using XDO type: XU BOOT | N COLDBOOT.COM
If your using 4DOS type: REBOOT | E 0100 48 50 53 CB 0D 0A
------------------------------------+ RCX
Flush your Disk Cache before you use| 0006
!!!! any of these methods !!!! | W
for Smartdrive this is: SMARTDRV /C | Q
2. COMMUNICATE WITH A MODEM
~~~~~~~~~~~~~~~~~~~~~~~~
Q: How do I communicate with my modem either in a BATch or on
the command-line ?
A: After setting up the COM port with MODE if required simply
use DOS redirection > to ECHO AT commands to it.
E.G. MODE COM1 baud=19200 data=8 parity=n stop=1
ECHO AT&FF10\N4&D3E0M0Q1S0=1&W0>COM1
might be used to set up a modem loading a profile into it
or if you wanted to leave a computer accessible from a
remote location you might shell out of a communications
program and run a batch file containing:
%COMSPEC% /e:1024 >COM1 <COM1
which would start a copy of the command processor to accept
input from the remote computer and output to it.
(with MS-DOS error messages would not get sent but 4DOS
allows STNDERR device writes to be re-directed)
3. DATE & TIME USE IN A BAT
~~~~~~~~~~~~~~~~~~~~~~~~
Q: How do I create a LogFile or get the current Time & Date
into environment variables.
A: A number of utilities to get the time or date into an
envar exist, among them are P2E, GET25, BATCHMAN & STRINGS
but a pure MS-DOS solution exists too:
VER|TIME|FIND "Current">$$TEMP$$.BAT
ECHO SET CTIME=%%3>CURRENT.BAT
$$TEMP$$.BAT
will place the current TIME into an envar called CTIME and
TIME can be replaced with DATE above to create CDATE.
To create a log of system boots the following could be
inserted into the AUTOEXEC.BAT file:
ECHO -=-=-=-=-=-=-=-=-=-=-=-=-=-=->>BOOTLOG.TXT
ECHO System booted !!! >>BOOTLOG.TXT : For more :
VER|TIME|FIND "Current">>BOOTLOG.TXT : techniques :
VER|DATE|FIND "Current">>BOOTLOG.TXT : type $ :
Using P2E to create filenames in YYMMDD.* format :
@ECHO OFF
ECHO.|DATE|P2E /E MM /L 1 /M 21,2 /E DD /L 1 /M 24,2 /E YY /L 1 /M 29,2
ECHO This is a New File>%YY%%MM%%DD%.TXT
Using PROMPT and CALL to create an 'ECHO'able Current Date & Time :
@ECHO OFF
ECHO @PROMPT LOG ON: $d at $t$h$h$h>C:\TEMP\TEMP$$$$.BAT
%COMSPEC% /C C:\TEMP\TEMP$$$$|FIND ":">>C:\LOGONS.TXT
Typical resultant contents of c:\logons.txt will be:
LOG ON: Fri 12-27-1993 at 09:37:48
LOG ON: Tue 01-04-1994 at 08:54:26
--etc.--etc.--
The section of the line between @PROMPT and the > is customizable
and all $codes valid for the PROMPT command can be used as well as
the current system date and time.
4. COMBINE FILES INTO ONE
~~~~~~~~~~~~~~~~~~~~~~
Q: I have lots of text files that I want to combine into one,
how can I automate this with a BATch.
A: The DOS COPY command can be used or redirection of TYPE's
output as follows:
COPY *.TXT ALL.XXX
RENAME ALL.XXX ALL.TXT
or
FOR %%f IN (*.TXT) DO TYPE %%f>>ALL.XXX
RENAME ALL.XXX ALL.TXT
The renaming of the resultant file is necessary, as when
it is created by the first COPY or TYPE operation, were
it called ALL.TXT it would immediately qualify for
inclusion in the command as it would match the filespec.
COPY can do binary concatenations too, with the /B param
MS-Windows remakes WIN.COM everytime Setup is used similar
to: COPY /B WIN.CNF+VGALOGO.LGO+VGALOGO.RLE WIN.COM
5. FORMATTING DISKS- Q & A
~~~~~~~~~~~~~~~~~~~~~~~
Q: How do I format a disk without DOS asking me questions ?
A: With MS-DOS 3.3 use FORMAT A: /H
With MS-DOS 4.0+ use FORMAT A: /AUTOTEST
!!! BEWARE - THIS WORKS ON HARD DISKS TOO !!!
There are a number of other undocumented switches for both
FORMAT and other MS-DOS features detailed in the MUF.
(For information about the MUF see item # 15. below)
6. GETTING ERRORLEVELS- Q & A
~~~~~~~~~~~~~~~~~~~~~~~~~~
Q: How do I echo the errorlevel returned by a program to the
screen so I can 'debug' my batch files ?
A: There are a couple of utilities that can do this but the
method used for the FAQ is the pure DOS solution below :
FOR %%E IN (0,1,2) DO IF ERRORLEVEL %%E00 SET ERLVL=%%E
IF "%ERLVL%"=="0" SET ERLVL=
SET RANGE=0,1,2,3,4,5,6,7,8,9
IF "%ERLVL%"=="2" SET RANGE=0,1,2,3,4,5
FOR %%E IN (%RANGE%) DO IF ERRORLEVEL %ERLVL%%%E0 SET ERLVL=%ERLVL%%%E
IF "%ERLVL%"=="0" SET ERLVL=
IF NOT "%ERLVL%"=="25" SET RANGE=0,1,2,3,4,5,6,7,8,9
FOR %%E IN (%RANGE%) DO IF ERRORLEVEL %ERLVL%%%E SET ERLVL=%ERLVL%%%E
SET RANGE=
ECHO Errorlevel is %ERLVL%
Here is a line-by-line walk thru' of this courtesy Rudy Lachin:
FOR %%E IN (0,1,2) DO IF ERRORLEVEL %%E00 SET ERLVL=%%E If errorlevel
is greater than 0 set ERLVL to 0, if >100 to 1 and if >200 to 2.
IF "%ERLVL%"=="0" SET ERLVL= If ERLVL=0 clear it (suppress leading 0)
SET RANGE=0,1,2,3,4,5,6,7,8,9 Now we've set the hundreds check tens
except when the errorlevel is >200 in which case we only want to go up
IF "%ERLVL%"=="2" SET RANGE=0,1,2,3,4,5 to the fifties.
FOR %%E IN (%RANGE%) DO IF ERRORLEVEL %ERLVL%%%E0 SET ERLVL=%ERLVL%%%E
If the errorlevel in this range of tens is above x00 set ERLVL to x00,
if > x10 set ERLVL to x10, if > x20 set ERLVL to x20, etc.
IF "%ERLVL%"=="0" SET ERLVL= If ERLVL=0 clear it (suppress